package com.ocom.oauth.controller;

import com.ocom.common.utils.RequestUtil;
import com.ocom.oauth.po.AiotLoginPo;
import com.ocom.oauth.po.LoginPo;
import com.ocom.oauth.utils.UrlUtil;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@Slf4j
@RestController
public class AiotLoginController {
    private final Logger log = LoggerFactory.getLogger(AiotLoginController.class);
    @PostMapping("/aiot/login")
    public String login(@Validated @RequestBody AiotLoginPo aiotLoginPo){
        Map<String,Object> requstMap =new HashMap<>();
        requstMap.put("grant_type",aiotLoginPo.getGrant_type());
        requstMap.put("client_id",aiotLoginPo.getClient_id());
        requstMap.put("client_secret",aiotLoginPo.getClient_secret());
        requstMap.put("account",aiotLoginPo.getAccount());
        requstMap.put("password",aiotLoginPo.getPassword());
        requstMap.put("verify",aiotLoginPo.getVerify());
        return RequestUtil.doPostForm(UrlUtil.getUrl()+"/login", requstMap);
    }
}
